<?php
include '../../include/config.php';

$menstrual = date('Y-d-m', strtotime($_COOKIE['mens']));
$duedate = date('Y-d-m',  strtotime($_COOKIE['duedate']));
$cycle = $_COOKIE['cycle'];
$ret = $_POST['ret'];
$chk = mysql_query("select * from baby_mother_last_period where bid = '".$_COOKIE['bid']."' ") or die(mysql_error());
if(mysql_num_rows($chk)!=0){
    while ($row = mysql_fetch_array($chk)) {
        mysql_query("delete from baby_mother_last_period where sr='".$row['sr']."'") or die(mysql_error());
    }
}
mysql_query("insert into baby_mother_last_period (`sr`,`bid`,`last_menstrual_period`,`due_date`,`cycle_length`) values(NULL,'".$_COOKIE['bid']."','".$menstrual."','".$duedate."','$cycle')" ) or die(mysql_error());
header("Location:$ret");
?>
